//导入
let{src,dest,watch}=require('gulp'),
sass =require('gulp-sass'),
cssnano =require('gulp-cssnano'),
rename = require('gulp-rename'),
htmlmin =require('gulp-htmlmin'),
uglify =require('gulp-uglify'),
imagemin =require('gulp-imagemin'),
babel= require('gulp-babel');

//任务
//复制
function fnCopyIndex(){
    return src('./src/index.html')
    .pipe(dest('./dist'));
}
//css
function fnCSS(){
    return src('./src/sass/*.scss')
    .pipe(sass({outputStyle: 'compressed'}))
    //  .pipe(cssnano())
    .pipe(rename({suffix:'.min'}))
    .pipe(dest('./dist/css'));
}

//js
function fnJS(){
return src('./src/js/*.js')
.pipe(babel({
    presets:['@babel/env']
}))
.pipe(uglify())
.pipe(rename({suffix:'.min'}))
.pipe(dest('./dist/js'));
}
//html
function fnPage(){
    return src('./src/page/*.html')
.pipe(htmlmin())
.pipe(dest('./dist/page'));

}
//img
function fnImg(){
    return src('./src/img/*')
    .pipe(imagemin())
    .pipe(dest('./dist/img'));
}
//watch
function fnWatch(){
watch('./src/index.html',fnCopyIndex)
watch('./src/img/*',fnImg);
watch('./src/js/*.js',fnJS);
watch('./src/page/*.html',fnPage);
watch('./src/sass/*.scss',fnCSS);

}
//导出
exports.copyIndex =fnCopyIndex;
exports.css = fnCSS;
exports.js = fnJS;
exports.html = fnPage;
exports.img = fnImg;
exports.default = fnWatch;




